package com.example.handle;

import com.example.common.Result;
import com.example.exceptions.BusinessException;
import com.example.exceptions.enumetation.ResponseEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author: sjz
 * @since: 2024/6/30 19:44
 */
@RestControllerAdvice
public class BaseExceptionHandle {

//    @ExceptionHandler(Exception.class)
//    public Result<Object> exceptionHandler(Exception e) {
//        e.printStackTrace();
//        return Result.error("服务器异常");
//    }

    @ExceptionHandler(BusinessException.class)
    public Result<Object> exceptionHandler(BusinessException e) {
        e.printStackTrace();
        return Result.error(e.getResponse());
    }

    @ExceptionHandler(SQLException.class)
    public Result<Object> exceptionHandler(SQLException e) {
        e.printStackTrace();
        ResponseEnum response = ResponseEnum.SERVER_BUSY;
        return Result.error(response);
    }



}
